package com.zx.config;

import com.zx.common.ResponseCommon;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionAdvice {


    @ExceptionHandler(value = Exception.class)
    public ResponseCommon<String> handlerException(HttpServletRequest request, Exception ex){
        ResponseCommon<String> response = new ResponseCommon<>();
        response.setCode(-1);
        response.setMessage("internal server error.. ");
        response.setData(ex.getMessage());
        log.error("系统错误,错误类型: [{}]",ex.getMessage());
        return response;
    }
}
